import string


# 任一个英文的纯文本文件，统计其中的单词出现的个数。

# 统计字母和单词出现的次数
def count():
    word_count = 0
    letter_count = 0
    inWord = False

    with open(r'text/RUNNING2.txt') as f:
        for line in f:
            for x in line:
                if x in string.ascii_letters:
                    letter_count = letter_count + 1
                    if not inWord:
                        word_count = word_count + 1
                        inWord = True
                else:
                    inWord = False

    print('单词数', word_count)
    print('字母数', letter_count)


count()
